package high;

import java.util.concurrent.*;

/**
 * @author 47868
 */
class task implements Callable<Integer> {
    private static int i = 1;
    @Override
    public Integer call() throws Exception {
        ThreadPool.println(Thread.currentThread().getName());
        i++;
        return this.i;
    }
}
public class ThreadPool {
    public static void println(Object msg){
        System.out.println(msg);
    }
    /*public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 10; i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    println("线程创建了");
                }
            });
        }
        executorService.shutdown();
    }*/
    public static void main(String[] args) throws Exception {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                10,20,10,TimeUnit.SECONDS,new ArrayBlockingQueue<>(10)
        );
        task task = new task();
        for (int i = 0; i < 100; i++) {
            Future<Integer> future=threadPoolExecutor.submit(task);
            TimeUnit.SECONDS.sleep(3);
            println(future.get());
        }
        threadPoolExecutor.shutdown();
    }
}
